package com.tongyi.lizhishop.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.widget.Toast;

import java.util.List;

/**
 * Created by zxc on 18/2/6.
 */

public class QQUtils {

    public static void startQQ(Context context){
        if(isQQClientAvailable(context)){
            final String qqUrl = "mqqwpa://im/chat?chat_type=wpa&uin=2869827829&version=1";
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(qqUrl)));
        }else{
            Toast.makeText(context,"请安装QQ客户端",Toast.LENGTH_SHORT).show();
        }
    }

    public static boolean isQQClientAvailable(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                if (pn.equals("com.tencent.mobileqq")) {
                    return true;
                }
            }
        }
        return false;
    }
}
